<template>
	<view>
		<view class="header">
			<image @click="back" class="back" src="../../static/tian/back.png" mode=""></image>
			<view class="text">{{$t('wallet.Transfer')}}</view>
			<image @click="toTime" class="time" src="../../static/img/time.png" mode=""></image>
		</view>
		<view style="height: 104rpx;"></view>
		<view class="item">
			<view class="title">{{$t('wallet.account')}}</view>
			<u-input class="uInput" v-model="name" :placeholder="$t('first.title4')"></u-input>
		</view>
		<view class="item">
			<view class="title">{{$t('wallet.amount')}}</view>
			<view style="margin-top: 15px;">
				<u-input class="uInput" v-model="num" :placeholder="$t('wallet.pleaseEntertheTransferAmount')">
					<template slot="suffix">
						<view class="flex" @click="show = true">
							<img v-if="select.logo" :src="baseurl + select.logo" alt="" style="width: 32rpx;height: 32rpx;">
							<view style="margin: 0 10rpx;">{{select.code}}</view>
							<img src="../../static/img/xia.png" alt="" style="width: 16rpx;height: 16rpx;">
						</view>
					</template>
				</u-input>
			</view>
		</view>
		<view class="Available">
			<text style="color: #a6a6a6;">{{$t('wallet.availableBalance')}}：</text>
			<text style="font-size: 28rpx;font-weight: 600;">{{select.balance}} {{select.code}}</text>
		</view>
		<view class="item">
			<view class="title">{{$t('wallet.enterPassword')}}</view>
			<view style="margin-top: 15px;">
				<u-input class="uInput" v-model="psd" :placeholder="$t('wallet.enterPassword')" type="password">
					<!-- <template slot="suffix">
						<text style="color: #ffb40f;font-weight: 600;" @click="forgotpsd">{{$t('wallet.forgetYourPassword')}}</text>
					</template> -->
				</u-input>
			</view>
		</view>
		<view class="txBtn" @click="submit">{{$t('wallet.confirmTheTransfer')}}</view>
		<u-picker :show="show" :columns="columns" @cancel="show = false" @confirm="confirm" keyName="code" :closeOnClickOverlay="true" @close="show = false"></u-picker>
	</view>
</template>

<script>
	import {domain} from '../../config/domain.js'
	export default {
		data() {
			return {
				show: false,
				columns: [],
				select:[],
				baseurl:'',
				
				name:'',
				psd:'',
				num:'',
				ok:true
			};
		},
		methods: {
			submit(){
				if(!this.ok){
					return;
				}
				this.ok = false;
				if (!this.name) {
					uni.showToast({
						icon:'none',
						title:this.$t('first.title4')
					}); 
					return false;
				}
				if (!this.num) {
					uni.showToast({
						icon:'none',
						title:this.$t('wallet.pleaseEntertheTransferAmount')
					}); 
					return false;
				}
				if (!this.psd) {
					uni.showToast({
						icon:'none',
						title:this.$t('first.title18')
					}); 
					return false;
				}
				var url = domain + 'api/new_transfer_accounts';
				var mytype = 'post';
				var userinfo = uni.getStorageSync('userinfo');
				var data={
					mobile:this.name,
					currency_id:this.select.id,
					amount:this.num,
					password:this.psd
				};
				uni.request({
					url,
					method: mytype,
					data,
					header: {
						'content-type': 'application/x-www-form-urlencoded' ,//自定义请求头信息
						'Lang':uni.getStorageSync('lang'),
						'AUTHORIZATION':userinfo.token,
					},
					success: res => {
						if(res.data.code == 0){
							uni.showToast({
								icon:'none',
								title:res.data.msg
							}); 
							this.ok = true;
						}else{
							uni.showToast({
								icon:'none',
								title:res.data.msg
							}); 
							setTimeout(function(){
								uni.navigateBack()
							},1000)
							
						}
					},
					fail: (err) => {
						console.log(err)
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
					}
				});
			},
			toTime() {
				uni.navigateTo({
					url: '/pages/index/cross?tab=50'
				})
			},
			back() {
				uni.navigateBack()
			},
			confirm(e){
				this.select = e.value[0];
				this.show = false;
			},
			forgotpsd(){
				uni.navigateTo({
					url:'../login/forgotpsd'
				})
			},
			getlist(){
				var url = domain + 'api/user/currency';
				var mytype = 'get';
				var userinfo = uni.getStorageSync('userinfo');
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true
				// });
				uni.request({
					url,
					method: mytype,
					header: {
						'content-type': 'application/x-www-form-urlencoded' ,//自定义请求头信息
						'Lang':uni.getStorageSync('lang'),
						'AUTHORIZATION':userinfo.token,
					},
					success: res => {
						this.columns.push(res.data.list1)
						this.select = res.data.list1[0]
					},
					fail: (err) => {
						console.log(err)
					},
					complete: () => {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
					}
				});
			},
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: this.$t('wallet.Transfer')
			});
			this.getlist()
			this.baseurl = domain
		}
	}
</script>
<style>
	.header {
		width: 100%;
		height: 104rpx;
		position: fixed;
		background-color: #ecf0f5;
		display: flex;
		top: 0;
		left: 0;
		align-items: center;
		justify-content: space-between;
		z-index: 999;
	}

	.header image {
		width: 48rpx;
		height: 48rpx;
	}

	.header .text {
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 600;
		color: #222;
	}

	.back {
		margin-left: 20rpx;
	}

	.time {
		margin-right: 20rpx;
	}
</style>
<style lang="scss">
	page {
		background-color: #ecf0f5;
	}

	.flex {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.item {
		width: 90%;
		padding: 20rpx;
		margin: 20rpx auto 50rpx;

		.title {
			font-size: 30rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #000;
		}


		.item2 {
			margin-top: 15px;
			background-color: #fff;
			height: 70rpx;
			border-radius: 20rpx;
			width: 90%;
			display: flex;
			align-items: center;
			padding: 0 20rpx;
		}



	}

	.Available {
		margin-left: 5%;
		font-size: 1rem;
		display: flex;
		align-items: center;
	}

	.txBtn {
		width: 90%;
		height: 96rpx;
		margin: 50rpx auto;
		background: #ffb105;
		border-radius: 50rpx;
		font-size: 36rpx;
		font-weight: 600;
		color: #000;
		text-align: center;
		line-height: 96rpx;
	}

	.uInput {
		background-color: #fff;
		margin-top: 10rpx;
		width: 90%;
		border-radius: 20rpx;
	}

	.balance {
		margin-top: 50rpx;
		width: 100%;
		box-shadow: 26rpx 26rpx 0 #f1f4f6;
		border-radius: 50rpx 50rpx 0 0;
		padding: 50rpx;
		box-sizing: border-box;
		background-color: #fff;
	}
</style>